package com.zxs.seckillweb.confiig;

import com.zxs.constant.Constants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    /**
     * 订单交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(Constants.EXCHANGE_NAME_ORDER);
    }

    /**
     * 订单队列
     * @return
     */
    @Bean
    public Queue orderQueue() {
        return new Queue(Constants.QUEUE_NAME_ORDER, true);
    }

    /**
     * 订单队列绑定交换机
     */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(orderQueue()).to(directExchange()).with(Constants.ROUTING_KEY_ORDER);
    }



}
